package com.aya.export.core;

import com.alibaba.excel.util.IoUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

// StreamingExporter.java
public class StreamingExporter implements Exporter {

    private final HttpServletResponse response;

    public StreamingExporter(HttpServletResponse response) {
        this.response = response;
    }

    @Override
    public String getMode() {
        return "STREAMING";
    }

    @Override
    public Object export(File localFile) throws IOException {
        response.setHeader("Content-Disposition", "attachment; filename=" + localFile.getName());
        response.setHeader("Content-Type", "application/octet-stream");
        try(final FileInputStream fileInputStream = new FileInputStream(localFile)){
            IoUtils.copy(fileInputStream, response.getOutputStream());
        }
        return null;
    }

}
